package com.seu.vcampus.view;

import com.seu.vcampus.client.VCampusClient;
import com.seu.vcampus.vo.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * 个人信息窗口
 * 独立的个人信息功能窗口
 * 
 * @author 虚拟校园开发团队
 * @since 2.1.0
 */
public class UserInfoFrame extends JFrame {
    private VCampusClient client;
    private User currentUser;
    
    public UserInfoFrame(VCampusClient client, User user) {
        super("个人信息 - " + user.getUsername());
        this.client = client;
        this.currentUser = user;
        
        initializeComponents();
        setupLayout();
        setupEventHandlers();
        
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setSize(500, 400);
        setLocationRelativeTo(null);
        setLocation(getX() + 50, getY() + 50); // 偏移显示
    }
    
    /**
     * 初始化组件
     */
    private void initializeComponents() {
        // 创建个人信息面板
        JPanel infoPanel = createUserInfoPanel();
        add(infoPanel);
    }
    
    /**
     * 创建个人信息面板
     */
    private JPanel createUserInfoPanel() {
        // 重用UserInfoPanel的完整功能
        return new UserInfoPanel(client, currentUser);
    }
    
    /**
     * 设置布局
     */
    private void setupLayout() {
        // 已经在initializeComponents中完成
    }
    
    /**
     * 设置事件处理器
     */
    private void setupEventHandlers() {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                // 窗口关闭时通知主界面
                dispose();
            }
        });
    }
}